<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>Getting Started</title>
			<link rel="stylesheet" href="../../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
			<div class="page-body">			
	<table class="tutorial-nav-box">
	<tr>
		<td style="width: 30%">
							<a href="../../event/event/tutorial_event.pkg.html" class="nav-button">Previous</a>
					</td>
		<td style="text-align: center">
							<a href="../../event/event/tutorial_event.pkg.html" class="nav-button">Up</a>
					</td>
		<td style="text-align: right; width: 30%">
							<a href="../../event/event/tutorial_adding-sources.pkg.html" class="nav-button">Next</a>
					</td>
	</tr>
	<tr>
		<td style="width: 30%">
							<span class="detail">Event User Guide</span>
					</td>
		<td style="text-align: center">
							<span class="detail">Event User Guide</span>
					</td>
		<td style="text-align: right; width: 30%">
							<span class="detail">Adding Sources to Event Handlers</span>
					</td>
	</tr>
</table>
	
<div><a name=""></a><div class="ref-title-box"><h1 class="ref-title">Getting Started</h1>
		<h2 class="ref-purpose"></h2></div>
	<div class="ref-synopsis"><span class="author">Gerrit Jan van Ahee
			<div class="author-blurb"><a href="mailto:gerrit.jan@yes2web.nl">Gerrit Jan van Ahee</a></div></span></div>
	<span><a name="basic-usage"></a><h2 class="title">Case</h2><p>There is a class called &quot;Listen_To_Me&quot; that should trigger events that are of use to a variety of other classes.
			For this exmaple, we are interested in when we are about to delete() and save() instances.
			<p><div class="title">Solution</div><p>First, we will create a listener to handle any events that are triggered by the Listen_To_Me class:
					<div class="src-code"><ol><li><div class="src-line"><span class="src-comm">#&nbsp;handles&nbsp;events&nbsp;triggered&nbsp;by&nbsp;Listen_To_Me,&nbsp;see&nbsp;listen/to/me.class.php</span></div></li>
<li><div class="src-line"><span class="src-key">class&nbsp;</span><span class="src-id">Listen_To_Me_Handler&nbsp;</span><span class="src-key">extends&nbsp;</span><a href="../../event/event/Event_Handler.html">Event_Handler</a>&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">#&nbsp;handles&nbsp;&quot;delete&quot;&nbsp;events</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">protected&nbsp;</span><span class="src-key">function&nbsp;</span><span class="src-id">onDelete</span><span class="src-sym">(</span><span class="src-id">Event_Event&nbsp;</span><span class="src-var">$oEvent</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">#&nbsp;supposing&nbsp;there&nbsp;is&nbsp;a&nbsp;Listen_To_Me-&gt;getId()&nbsp;method</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<span class="src-str">'About&nbsp;to&nbsp;delete&nbsp;'</span>.<span class="src-var">$oEvent</span><span class="src-sym">-&gt;</span><span class="src-id">getSource</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">getId</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;&nbsp;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">#&nbsp;handles&nbsp;&quot;save&quot;&nbsp;events</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">protected&nbsp;</span><span class="src-key">function&nbsp;</span><span class="src-id">onSave</span><span class="src-sym">(</span><span class="src-id">Event_Event&nbsp;</span><span class="src-var">$oEvent</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">#&nbsp;supposing&nbsp;there&nbsp;is&nbsp;a&nbsp;Listen_To_Me-&gt;getId()&nbsp;method</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<span class="src-str">'About&nbsp;to&nbsp;save&nbsp;'</span>.<span class="src-var">$oEvent</span><span class="src-sym">-&gt;</span><span class="src-id">getSource</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">-&gt;</span><span class="src-id">getId</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;&nbsp;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><span class="src-sym">}</span></div></li>
</ol></div></p>
				<p>Should the Listen_To_Me class trigger any other events: these will be noticed by Listen_To_Me_Handler, but ignored.</p>
				<p>Next, the Listen_To_Me class will trigger the required events:
					<div class="src-code"><ol><li><div class="src-line"><span class="src-key">class&nbsp;</span><span class="src-id">Listen_To_Me&nbsp;</span><span class="src-key">extends&nbsp;</span><span class="src-id">Whatever_You_Like&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">#...</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><span class="src-id">delete</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../../event/event/Event_Event.html">Event_Event</a></span><span class="src-sym">(</span><span class="src-str">'delete'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">#&nbsp;...</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><span class="src-id">save</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">{</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../../event/event/Event_Event.html">Event_Event</a></span><span class="src-sym">(</span><span class="src-str">'save'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">#&nbsp;...</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line">&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">#...</span></div></li>
<li><div class="src-line"><span class="src-sym">}</span></div></li>
</ol></div></p>
				<p>Finally, we should have the Listen_To_Me_Handler listen to Listen_To_Me classes. This is done by simply providing the classname during
					construction (as a string):
					<div class="src-code"><ol><li><div class="src-line"><span class="src-key">new&nbsp;</span><span class="src-id">Listen_To_Me_Handler</span><span class="src-sym">(</span><span class="src-str">'Listen_To_Me'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
</ol></div></p></p></p></span></div>

	<table class="tutorial-nav-box">
	<tr>
		<td style="width: 30%">
							<a href="../../event/event/tutorial_event.pkg.html" class="nav-button">Previous</a>
					</td>
		<td style="text-align: center">
							<a href="../../event/event/tutorial_event.pkg.html" class="nav-button">Up</a>
					</td>
		<td style="text-align: right; width: 30%">
							<a href="../../event/event/tutorial_adding-sources.pkg.html" class="nav-button">Next</a>
					</td>
	</tr>
	<tr>
		<td style="width: 30%">
							<span class="detail">Event User Guide</span>
					</td>
		<td style="text-align: center">
							<span class="detail">Event User Guide</span>
					</td>
		<td style="text-align: right; width: 30%">
							<span class="detail">Adding Sources to Event Handlers</span>
					</td>
	</tr>
</table>
	
	<p class="notes" id="credit">
		Documentation generated on Fri, 28 Jan 2011 10:33:55 +0100 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.3</a>
	</p>
	</div></body>
</html>